package com.founder.android.reader.adapter;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.founder.android.reader.bean.BookMark;

public class BookMarkAdapter extends BaseAdapter {
	private List<BookMark> markList = new ArrayList<BookMark>();
	private Context mContext;
	
	public BookMarkAdapter(Context context,List<BookMark> list) {
		super();
		markList.addAll(list);
		mContext = context;
	}
	public BookMarkAdapter(Context context,BookMark mark) {
		super();
		markList.add(mark);
		mContext = context;
	}
	
	public BookMarkAdapter(Context context) {
		super();
		mContext = context;
	}
	
	public void addMark(List<BookMark> list){
		markList.addAll(list);
		this.notifyDataSetChanged();
	}
	
	public void addMark(BookMark mark){
		markList.add(mark);
		this.notifyDataSetChanged();
	}
	
	public void deleteMark(int position){
		markList.remove(position);
		this.notifyDataSetChanged();
	}
	
	public void removeAll(){
		markList.clear();
		this.notifyDataSetChanged();
	}
	
	@Override
	public int getCount() {
		return markList.size();
	}

	@Override
	public BookMark getItem(int position) {
		return markList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		View view = convertView;
		if(view == null){
			view = new TextView(mContext);
			
		}
		((TextView)view).setText(markList.get(position).mark);
		((TextView)view).setBackgroundColor(Color.WHITE);
		((TextView)view).setTextColor(Color.BLACK);
		((TextView)view).setTextSize(19);
		((TextView)view).setPadding(20, 5, 20, 5);
		((TextView)view).setFocusable(false);

		return view;
	}
}
